package com.lrkj.payfee.controller;

import com.lrkj.common.annotation.Log;
import com.lrkj.common.core.controller.BaseController;
import com.lrkj.common.core.domain.AjaxResult;
import com.lrkj.common.core.page.TableDataInfo;
import com.lrkj.common.enums.BusinessType;
import com.lrkj.common.utils.poi.ExcelUtil;
import com.lrkj.payfee.domain.FiscalRecord;
import com.lrkj.payfee.service.IFiscalRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 结账记录Controller
 *
 * @author yajun_ren
 * @date 2022-03-28
 */
@RestController
@RequestMapping("/payfee/fiscalRecord")
@Api(tags = "结账记录")
public class FiscalRecordController extends BaseController {
    @Autowired
    private IFiscalRecordService fiscalRecordService;

    /**
     * 查询结账记录列表
     */
    @ApiOperation(value = "查询结账记录列表", notes = "查询结账记录列表")
    @PreAuthorize("@ss.hasPermi('payfee:fiscalRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(FiscalRecord fiscalRecord) {
        startPage();
        this.changeParameter(fiscalRecord.getParams());
        List<FiscalRecord> list = fiscalRecordService.selectFiscalRecordList(fiscalRecord);
        return getDataTable(list);
    }

    /**
     * 导出结账记录列表
     */
    @ApiOperation(value = "导出结账记录列表", notes = "导出结账记录列表")
    @PreAuthorize("@ss.hasPermi('payfee:fiscalRecord:export')")
    @Log(title = "结账记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FiscalRecord fiscalRecord) {
        List<FiscalRecord> list = fiscalRecordService.selectFiscalRecordList(fiscalRecord);
        ExcelUtil<FiscalRecord> util = new ExcelUtil<FiscalRecord>(FiscalRecord.class);
        return util.exportExcel(list, "结账记录数据");
    }

    /**
     * 获取结账记录详细信息
     */
    @ApiOperation(value = "获取结账记录详细信息", notes = "获取结账记录详细信息")
    @PreAuthorize("@ss.hasPermi('payfee:fiscalRecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(fiscalRecordService.selectFiscalRecordById(id));
    }

    /**
     * 新增结账记录
     */
    @ApiOperation(value = "新增结账记录", notes = "新增结账记录")
    @PreAuthorize("@ss.hasPermi('payfee:fiscalRecord:add')")
    @Log(title = "结账记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FiscalRecord fiscalRecord) {
        return toAjax(fiscalRecordService.insertFiscalRecord(fiscalRecord));
    }

    /**
     * 修改结账记录
     */
    @ApiOperation(value = "修改结账记录", notes = "修改结账记录")
    @PreAuthorize("@ss.hasPermi('payfee:fiscalRecord:edit')")
    @Log(title = "结账记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FiscalRecord fiscalRecord) {
        return toAjax(fiscalRecordService.updateFiscalRecord(fiscalRecord));
    }

    /**
     * 删除结账记录
     */
    @ApiOperation(value = "删除结账记录", notes = "删除结账记录")
    @PreAuthorize("@ss.hasPermi('payfee:fiscalRecord:remove')")
    @Log(title = "结账记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(fiscalRecordService.deleteFiscalRecordByIds(ids));
    }

    /**
     * 结账前检查
     */
    @ApiOperation(value = "结账前检查", notes = "结账前检查")
    @PreAuthorize("@ss.hasPermi('payfee:fiscalRecord:fiscalBeforeCheck')")
    @PostMapping("/fiscalBeforeCheck")
    public AjaxResult fiscalBeforeCheck(@RequestBody FiscalRecord fiscalRecord) {
        return AjaxResult.success(fiscalRecordService.fiscalBeforeCheck(fiscalRecord));
    }


    /**
     * 结账
     */
    @ApiOperation(value = "结账", notes = "结账")
    @PreAuthorize("@ss.hasPermi('payfee:fiscalRecord:fiscal')")
    @PostMapping("/fiscal")
    public AjaxResult fiscal(@RequestBody FiscalRecord fiscalRecord) {
        return AjaxResult.success(fiscalRecordService.fiscal(fiscalRecord));
    }


    /**
     * 反结账
     */
    @ApiOperation(value = "反结账", notes = "反结账")
    @PreAuthorize("@ss.hasPermi('payfee:fiscalRecord:backFiscal')")
    @PostMapping("/backFiscal")
    public AjaxResult backFiscal(@RequestBody FiscalRecord fiscalRecord) {
        return AjaxResult.success(fiscalRecordService.backFiscal(fiscalRecord));
    }


}
